package test.cor;

import java.util.LinkedList;
import java.util.List;

public class FilterChain implements Filter {
	private LinkedList<Filter> list = new LinkedList<>();
	@Override
	public boolean doFilter(MyRequest request, MyResponse response, FilterChain chain) {
		for (Filter filter : list) {
			boolean doFilter = filter.doFilter(request, response, chain);
			if(!doFilter) {
				return false;
			}
		}
		return true;
	}

	public FilterChain add(Filter filter) {
		 list.add(filter);
		 return this;
	}
	public FilterChain remove(Filter filter) {
		list.remove(filter);
		return this;
	}
	public boolean hashNext() {
		return !list.isEmpty();
	}
	public Filter getFilter() {
		return list.getFirst();
	}
}
